/**
 * 
 */
package action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import myfamily.model.Contact;
import myfamily.model.GenericPerson;
import myfamily.model.Name;
import myfamily.model.RegisteredUser;

import org.expressme.openid.Authentication;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author JATIN
 *
 */
public class StartCreateTree extends ActionSupport{

	private List<String> operations;
	private List<String> familymembers;
	private String create;
	private RegisteredUser rUser;
	private String treeString;
	private String authId;
	public String execute(){

		try{
			Map session = ActionContext.getContext().getSession();
			Authentication auth = new Authentication();
			auth = (Authentication)session.get("authentication");
			setAuthId(auth.getIdentity().split("=")[1]);
			System.out.println("In create tree");

			RegisteredUser ru = new RegisteredUser(getAuthId(),getAuthId(),"",new Name(auth.getFirstname(),"",auth.getLastname()),auth.getGender(),"","",null,null,(new Contact("",auth.getEmail())));

			setTreeString(ru.printTree().toString());
			System.out.println(getTreeString());
			operations = new ArrayList<String>();

			operations.add("Add Child");
			operations.add("Add Parents");
			operations.add("Add Partner");
			operations.add("Add Sibling");
			operations.add("Delete Member");
			operations.add("Edit Details");

			familymembers = new ArrayList<String>();
			familymembers.clear();
			ArrayList<GenericPerson> fm = ru.identifyExtremeAncestors();
			for(GenericPerson g: fm){
				familymembers.add(g.getPersonName().toString());

			}

		}catch(Exception e){

			addActionError("User already exists");

		}

		return SUCCESS;

	}

	public String getCreate() {
		return create;
	}

	public void setCreate(String create) {
		this.create = create;
	}

	public RegisteredUser getrUser() {
		return rUser;
	}

	public void setrUser(RegisteredUser rUser) {
		this.rUser = rUser;
	}

	public String getTreeString() {
		return treeString;
	}

	public void setTreeString(String treeString) {
		this.treeString = treeString;
	}

	public List<String> getOperations() {
		return operations;
	}

	public void setOperations(List<String> operations) {
		this.operations = operations;
	}

	public List<String> getFamilymembers() {
		return familymembers;
	}

	public void setFamilymembers(List<String> familymembers) {
		this.familymembers = familymembers;
	}

	public String getAuthId() {
		return authId;
	}

	public void setAuthId(String authId) {
		this.authId = authId;
	}

}
